package com.example.config.resp;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class RespJsonUtil {

	private RespJsonUtil() {}
	
	private static final Logger LOG = LoggerFactory.getLogger(RespJsonUtil.class);
	
	private static final ObjectMapper objectMapper = new ObjectMapper();
	
	static {
		/** DefaultSerializerProvider sp = new DefaultSerializerProvider.Impl(); **/
		CustomSerializerProvider sp = new CustomSerializerProvider();
		objectMapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
		objectMapper.setSerializerProvider(sp);
	}

	public static String writeValueAsString(Object o) {
		try {
			return objectMapper.writeValueAsString(o);
		} catch (JsonProcessingException e) {
			LOG.error(ExceptionUtils.getFullStackTrace(e));
			return null;
		}
	}

}
